#include <bits/stdc++.h>
#define re register
#define fst first
#define snd second
#define int long long

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> pip;
const int N = 5e5 + 10;
const int inf = (int)(1e18) + 10;
int n,m;
int arr[N],L[N],R[N];
set<pip> st;

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline void remove(int x){
    int l = L[x],r = R[x];
    L[r] = l,R[l] = r;
    st.insert({arr[l] + arr[r],{min(l,r),max(l,r)}});
    st.erase({arr[l] + arr[x],{min(l,x),max(l,x)}});
    st.erase({arr[x] + arr[r],{min(x,r),max(x,r)}});
}

signed main(){
    freopen("sub.in","r",stdin);
    freopen("sub.out","w",stdout);
    n = read(),m = read();
    for (re int i = 1;i <= n;i++) arr[i] = read();
    for (re int i = 1;i < n;i++) R[i] = i + 1;
    for (re int i = 2;i <= n;i++) L[i] = i - 1;
    R[L[1] = n] = 1; st.insert({arr[1] + arr[n],{1,n}});
    for (re int i = 2;i <= n;i++) st.insert({arr[i - 1] + arr[i],{i - 1,i}});
    for (re int t = 1;t <= n - m;t++){
        pip p = *st.rbegin();
        if (arr[p.snd.fst] > arr[p.snd.snd]) remove(p.snd.fst);
        else remove(p.snd.snd);
    } printf("%lld",(*st.rbegin()).fst);
    return 0;
}